package architect.design.patterns.creation.singleton;

/**
 * 静态初始化块单例
 *
 * @author guanxin
 * @date 2018/5/4 11:03
 */

public class StaticBlockSingleton {

    private static final StaticBlockSingleton INSTANCE;

    // 私有构造函数，避免被客户端使用
    private StaticBlockSingleton() {}

    static {
        try {
            INSTANCE = new StaticBlockSingleton();
        } catch (Exception e) { // 异常处理
            throw new RuntimeException("初始化失败", e);
        }
    }

    public static StaticBlockSingleton getInstance() {
        return INSTANCE;
    }
}
